package course_hashMap;
import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
public class Hash2 {
    public static void main(String[] args) {
        Map<String,Hero> HeroHashMap1 =new HashMap<>();
        Map<String,Hero> HeroHashMap2 =new HashMap<>();
        Map<String,Hero> HeroHashMap3 =new HashMap<>();
        Map<String,Hero> HeroHashMap4 =new HashMap<>();
        Map<String,Hero> HeroHashMap5 =new HashMap<>();
        Hero liubei=new Hero();
        Hero guanyu=new Hero();
        Hero zhangfei=new Hero();
        Hero huamulan=new Hero();
        Hero sulie=new Hero();
        Hero bailishouyue=new Hero();
        Hero daji=new Hero();
        Hero mengqi=new Hero();
        Hero peiqinghu=new Hero();
        liubei.setAll("刘备",35,"射手");
        HeroHashMap1.put(liubei.getName(),liubei);

        zhangfei.setAll("张飞",33,"辅助");
        HeroHashMap4.put(zhangfei.getName(),zhangfei);

        guanyu.setAll("关羽",34,"战士");
        HeroHashMap2.put(guanyu.getName(),guanyu);

        sulie.setAll("苏烈",45,"肉盾");
        HeroHashMap5.put(sulie.getName(),sulie);

        huamulan.setAll("花木兰",23,"战士");
        HeroHashMap2.put(huamulan.getName(),huamulan);

        bailishouyue.setAll("百里守约",19,"射手");
        HeroHashMap1.put(bailishouyue.getName(),bailishouyue);

        daji.setAll("妲己",18,"法师");
        HeroHashMap3.put(daji.getName(),daji);

        mengqi.setAll("梦奇",12,"肉盾");
        HeroHashMap5.put(mengqi.getName(),mengqi);

        peiqinghu.setAll("裴擒虎",26,"射手");
        HeroHashMap1.put(peiqinghu.getName(),peiqinghu);
        //放一个hashMap里
        Map<String,Map<String,Hero>>hashMap =new HashMap<>();
        hashMap.put("射手",HeroHashMap1);
        hashMap.put("战士",HeroHashMap2);
        hashMap.put("法师",HeroHashMap3);
        hashMap.put("辅助",HeroHashMap4);
        hashMap.put("肉盾",HeroHashMap5);
        //嵌套遍历
        // 获取外层集合键集合set1。
        Set<String> set1 = hashMap.keySet();
        for (String ch : set1) {
            System.out.print(ch);
            // 通过多层集合的键获取内层存储英雄信息的集合对象。
            Map<String, Hero> inHashMap = hashMap.get(ch);
            // 获取内层存储英雄信息集合的键的集合
            Set<String> set2 = inHashMap.keySet();
            for (String key : set2) {
                System.out.print("   " + key + "(年龄" + inHashMap.get(key).getAge()+")、");
            }
            System.out.println();
        }
    }
}
